//
//  Statuses.swift
//  HYYWeibo
//
//  Created by HY-Mac on 16/7/16.
//  Copyright © 2016年 HY-Mac. All rights reserved.
//

import UIKit

class Statuses: NSObject {
    /// 微博创建时间
    var created_at: String?{
        didSet{
            if let timeStr = created_at{
                
                //timeStr = "Sun Jul 15 11:10:41 +0800 2016"
                let createDate = NSDate.createWeiboDateFromString(timeStr, formatStr: "EE MM dd HH:mm:ss Z yyyy")
                
                
                createTimeStr = NSDate().createWeiboTimeString(createDate)
            }
        }
    }
    
    var createTimeStr: String?
    
    /// 字符串型的微博ID
    var idstr: String?
    
    /// 微博信息内容
    var text: String?
    
    /// 微博来源
    var source: String?{
        didSet{
            if let sourceStr: NSString = source where sourceStr != ""{
                let startIndex = sourceStr.rangeOfString(">").location + 1
                let length = sourceStr.rangeOfString("<", options: .BackwardsSearch).location - startIndex
                source_readableStr = "来自: " + sourceStr.substringWithRange(NSMakeRange(startIndex, length))
            }
        }
    }
    
    var source_readableStr: String?
    
    var user: User?
    
    
    init(dict: [String: AnyObject])
    {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            user = User(dict: value as! [String: AnyObject])
            return
        }
        super.setValue(value, forKey: key)
    }
    
    override var description: String {
        let property = ["created_at", "idstr", "text", "source"]
        let dict = dictionaryWithValuesForKeys(property)
        return "\(dict)"
    }
    

    

}
